#include "syscall.h"

/*Testing out Conditions*/

int WakeUp()
{
	Write("I will wake him up\n",19,ConsoleOutput);
	Signal(0,0);
	Exit(0);
}

int Waiter1()
{
	Acquire(0);
	Write("I am going to sleep 1\n",22,ConsoleOutput);
	Wait(0,0);
	Write("I have been awakened 1\n",23,ConsoleOutput);
	Exit(0);
}
int Waiter2()
{
	Acquire(0);
	Write("I am going to sleep 2\n",22,ConsoleOutput);
	Wait(0,0);
	Write("I have been awakened 2\n",23,ConsoleOutput);
	Exit(0);
}
int Waiter3()
{
	Acquire(0);
	Write("I am going to sleep 3\n",22,ConsoleOutput);
	Wait(0,0);
	Write("I have been awakened 3\n",23,ConsoleOutput);
	Exit(0);
}

int main()
{
	int condNum=2;
	CreateLock("Lock",4);
	CreateCondition("Cond",4);
	/*Acquire(0);
	Fork(WakeUp);
	Write("I am going to sleep\n",20,ConsoleOutput);
	Wait(0,0);
	Write("I have been awakened\n",21,ConsoleOutput);
	Release(0);*/
	
	Fork(Waiter1);
	Yield();
	Fork(Waiter2);
	Yield();
	Fork(Waiter3);
	Yield();
	Write("I will wake him up\n",19,ConsoleOutput);
	Broadcast(0,0);
	
	
	/*DestroyCondition(0);*/

	/*attempting to manipulate a condition that doesn't exist*/
	
	/*Wait(condNum,0);
	Signal(condNum,0);
	DestroyCondition(condNum);*/
	
	/*creating a Condition to test*/
	
	/*
	condNum=CreateLock("Lock Name",9);
	if(condNum==1)
	{
		Write("Cond Created\n",13, ConsoleOutput );
	}
	DestroyCondition(condNum);
	*/
	
	/*make sure that you can't do anything with a deleted lock*/
	
	/*
	Wait(condNum,0);
	Signal(condNum,0);
	DestroyCondition(condNum);
	*/
	
	Exit(0);
}

